package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.BookDao;
import com.itheima.dao.ReturnDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Borrow;
import com.itheima.pojo.Search;
import com.itheima.pojo.User;
import com.itheima.service.BookBorrowService;
import com.itheima.service.BookReturnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = BookReturnService.class)
@Transactional
public class BookReturnServiceImpl implements BookReturnService {
    @Autowired
    private ReturnDao returnDao;
    //分页查询
    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();

        PageHelper.startPage(currentPage,pageSize);
        Page<Search> page = returnDao.selectByCondition(queryString);
        long total = page.getTotal();
        List<Search> rows = page.getResult();
        return new PageResult(total,rows);
    }

    @Override
    public Borrow findById(Integer book_id) {
        return returnDao.findById(book_id);
    }

    @Override
    public void delete(Integer book_id) {
        returnDao.delete(book_id);
    }

    @Override
    public void update(Integer book_id) {
        returnDao.update(book_id);
    }

    @Override
    public void insert(Borrow borrow) {
        returnDao.insert(borrow);
    }

    @Override
    public void updatenumber(User user) {
        returnDao.updatenumber(user);
    }

}
